package com.netty.server.handler;

import com.netty.entity.Person;
import io.netty.buffer.Unpooled;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandler;

import java.io.BufferedReader;
import java.io.InputStreamReader;

/**
 * @author xurongbei
 */
@ChannelHandler.Sharable
public class PersonServerHandler extends MyHandler<Person> {

    @Override
    public void channelRead(Channel channel, Person msg) {
        try {
            System.out.println("from client:" + msg.getName());
            if ("exit".equals(msg.getName())) {
                channel.close();
                System.out.println("连接关闭");
                return;
            } else {
                System.out.println("to client");
                /*BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
                String line = br.readLine();
                channel.writeAndFlush(Unpooled.copiedBuffer(line.getBytes("UTF-8")));*/
            }
        }catch (Exception e){
            e.printStackTrace();
        }

    }
}
